// /////////////////////////////////////////////////////////////////////////////
// r1 group ////////////////////////////////////////////////////////////////////
// /////////////////////////////////////////////////////////////////////////////
$.fn.getR1data = function(_lotto_id, _gametype){
 $().disAreaObj();
 $.getJSON('op.php?op=xml_3d&fp=rate_3d&playtype=r1&lotto_id_3d=' + _lotto_id + "&gametype=" + _gametype + "&disk="+ $("select#slcDisk").val() ,function(ratedata){
      var dataLen = 0;
      var urlPre = "";
      var hrefStr = "";
      var palygroup = "r1";
      
      if(ratedata.errormsg != undefined){
        $("div#errormsg").addClass("error").text("No Rate data");
      }else{
        var disk = $("select#slcDisk").val(); 
        
        $().showTableData(ratedata.r55_0,"r55",disk,_gametype,palygroup,'55_0');
        
        // two face     
        $().showTabelDataTwoFace(ratedata.r4_0,"tblNowBet02",disk,_gametype,palygroup,'4_0');    
        $().showTabelDataTwoFace(ratedata.r5_0,"tblNowBet02",disk,_gametype,palygroup,'5_0');
        $().showTabelDataTwoFace(ratedata.r6_0,"tblNowBet02",disk,_gametype,palygroup,'6_0');
        $().showTabelDataTwoFace(ratedata.r7_0,"tblNowBet02",disk,_gametype,palygroup,'7_0');
        $().showTabelDataTwoFace(ratedata.r8_0,"tblNowBet02",disk,_gametype,palygroup,'8_0');
        $().showTabelDataTwoFace(ratedata.r9_0,"tblNowBet02",disk,_gametype,palygroup,'9_0');
        $().showTabelDataTwoFace(ratedata.r10_0,"tblNowBet02",disk,_gametype,palygroup,'10_0');
        $().showTabelDataTwoFace(ratedata.r11_0,"tblNowBet02",disk,_gametype,palygroup,'11_0');            
        $().showTabelDataTwoFace(ratedata.r12_0,"tblNowBet02",disk,_gametype,palygroup,'12_0');
        
        $().showTabelDataTwoFace(ratedata.r56_0,"tblNowBet02",disk,_gametype,palygroup,'56_0');
        $().showTabelDataTwoFace(ratedata.r57_0,"tblNowBet02",disk,_gametype,palygroup,'57_0');
        $().showTabelDataTwoFace(ratedata.r58_0,"tblNowBet02",disk,_gametype,palygroup,'58_0');
        $().showTabelDataTwoFace(ratedata.r59_0,"tblNowBet02",disk,_gametype,palygroup,'59_0');
        $().showTabelDataTwoFace(ratedata.r60_0,"tblNowBet02",disk,_gametype,palygroup,'60_0');
        $().showTabelDataTwoFace(ratedata.r61_0,"tblNowBet02",disk,_gametype,palygroup,'61_0');
   }
   
   $().redisAreaObj();
   $("div#mainPageData").show();
   $("div#errormsg").text("");
   // change text or checkbox type
    var timebtnType = $("input:hidden#timebtnType").val();
    if(timebtnType == "checkbox"){
      $().timebtnTypeToCheckbox(); 
    }
    
    $("table#tblNowBet02 td:has(input)").parent("tr.td2").hover(
      function() {$(this).children().addClass("trover");}
      , function() {$(this).children().removeClass("trover");}
    );
    
    // check rate each 30 sec
    //renewRateTimeObj = setTimeout(function(){$().renewR1data(_lotto_id,_gametype);}, renewRateTime);  
    
  });
};


// renew the rate at r1
$.fn.renewR1data = function(_lotto_id,_gametype){
 $.getJSON('op.php?op=xml_3d&fp=rate_3d&playtype=r1&lotto_id_3d='+_lotto_id+'&gametype='+_gametype+'&disk='+$("select#slcDisk").val() ,function(ratedata){
      var dataLen = 0;
      var urlPre = "";
      var hrefStr = "";
      if(ratedata.errormsg != undefined){
        $("div#errormsg").addClass("error").text("No Rate data");
      }else{
        
        // check rate bettype index 
        $().checkRateChg("r1",ratedata.r1);
        $().checkRateChg("r2",ratedata.r2);
        $().checkRateChg("r3",ratedata.r3);
        $().checkRateChg("r0",ratedata.r0);
        
        $().checkRateChg("r4",ratedata.r4);
        $().checkRateChg("r5",ratedata.r5);
        $().checkRateChg("r6",ratedata.r6);
        $().checkRateChg("r7",ratedata.r7);
        $().checkRateChg("r8",ratedata.r8);
        $().checkRateChg("r9",ratedata.r9);
        $().checkRateChg("r10",ratedata.r10);
        $().checkRateChg("r11",ratedata.r11);
        $().checkRateChg("r12",ratedata.r12);
        
        $().checkRateChg("r22",ratedata.r22);
        $().checkRateChg("r23",ratedata.r23);
        
        // renew again
        //renewRateTimeObj = setTimeout(function(){$().renewR1data(_lotto_id);}, renewRateTime);
      }  
    
  });
};


// check rate
$.fn.checkRateChg = function(tbdId,ratedata){
  var dataLen = ratedata.number.length;
  var tbd = "tbody#" + tbdId;
  var strIdx = "";
  var tempUrl;
  $(tbd + " td[class=betnum alert1]").removeClass("alert1");
  for(i = 0; i < dataLen; i++){
    if($(tbd + " tr:eq("+i+")>td>a:first").text() != ratedata.rates[i]){
      $(tbd + " tr:eq("+i+")>td>a:first").text(ratedata.rates[i]).parent("td").addClass("alert1");
      tempUrl = $(tbd + " tr:eq("+i+")>td>a:first").attr("href");
      strIdx = tempUrl.search("&rate=");
      if(strIdx>-1){$(tbd + " tr:eq("+i+")>td>a:first").attr("href",tempUrl.substr(0,strIdx)+"&rate="+ratedata.rates[i]);}
    }
  }
};

// show table data two face
/*
$.fn.showTabelDataTwoFace = function(rdata,tbdId,disk,_gametype,palygroup,bettype){
  var dataLen = rdata.number.length;
  var tbd = "tbody#" + tbdId;
    urlPre = "op.php?op=member_3d&fp=bet_fast&gametype="+_gametype+"&palygroup="+palygroup+"&bettype="+bettype+"&disk="+disk;
    for(i = 0; i < dataLen; i++){
      hrefStr = urlPre + "&num=" + rdata.number[i] + "&rate=" + rdata.rates[i];
    $(tbd+" tr:nth-child(" +rdata.number[i] + ")>td:nth-child(2)").html('<a href="'+hrefStr+'" class=\"betRateNum\" target=\"leftFrame\">'+ rdata.rates[i] +'</a>');}
    
};
*/